Socket
Socket
Sign inDemoInstall

fastqueue

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastqueue

A fast push/shift sync queue


Version published
Maintainers
1
Created
Source

Fast Queue

While normal JavaScript arrays can be used as FIFO queues, the .shift() call is very slow if the queue gets large because it has to reindex all the remaining items on every shift.

This library is a fast queue that only implements .push(item), .shift(), .unshift(item) and .length from the Array interface.

Internally it uses two arrays and cycles them and uses counters so that the .shift() calls are still fast.

Usage

var Queue = require('fastqueue');

var q = new Queue;
q.push(1);
q.push(2);
q.push(3);
var i = 4;
while (q.length > 0) {
  console.log(q.length, q.shift());
  q.unshift(i++);
  console.log(q.length, q.shift());
  q.push(i++);
  console.log(q.length, q.shift());
}

FAQs

Package last updated on 02 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc